
import {$} from "../util/seq.js";
import {defineButton} from "./buttons.js";

export function defineStatusCard(container, sessionStore) {
    const field = container.select(".field");
    const closeButton = container.select("button");

    function updateDOM() {
        const message = sessionStore.get("error") ?? sessionStore.get("status");
        container.property("hidden", (message ?? "") === "");
        field.text(message);
    }

    sessionStore.on($`change:status change:error`, updateDOM);
    defineButton(closeButton, () => sessionStore.save({status: undefined, error: undefined}));
}
